<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>计算机</title>
		<link rel="stylesheet" type="text/css" href="css/main.css" />
	</head>
	<body>
		
		<button onclick="openBox()">点击计算机</button>
		
		<div id="box" >
			<h1>计算机</h1>
			<span id="close" onclick="closeBox()">&times;</span>
			
			<hr />
			<input id="ipt" type="text" placeholder="欢迎使用计算器" />
			
			<div class="btn-box">
				<input type="button" value="0" onclick="calc('0')"/>
				<input type="button" value="1" onclick="calc('1')"/>
				<input type="button" value="2" onclick="calc('2')"/>
				<input type="button" value="3" onclick="calc('3')"/>
				<input type="button" value="4" onclick="calc('4')"/>
				<input type="button" value="5" onclick="calc('5')"/>
				<input type="button" value="6" onclick="calc('6')"/>
				<input type="button" value="7" onclick="calc('7')"/>
				<input type="button" value="8" onclick="calc('8')"/>
				<input type="button" value="9" onclick="calc('9')"/>
				<input type="button" value="+" onclick="calc('+')"/>
				<input type="button" value="-" onclick="calc('-')"/>
				<input type="button" value="*" onclick="calc('*')"/>
				<input type="button" value="/" onclick="calc('/')"/>
				<input type="button" value="c" onclick="calc('c')"/>
				<input type="button" value="=" onclick="calc('=')"/>
			</div>
			
		</div>
		
		
		
		<script>
			
			// function a(){
			// 	alert("sadsa");
			// 	alert("sa66232");
			// 
			
			
			// 带参数的函数
			//参数：num
			// function a(num1,num2){
			// 	alert(num1 + num2);
			// }
			
			//1.点击close
			//2.关闭
			function calc(key){
				// switch选择
				var ipt = document.getElementById("ipt");
				switch(key){
					case "c":
						ipt.value = "";
						break;
					
					case "=":
						ipt.value = eval(ipt.value);
						break;
					
					default:
						ipt.value = ipt.value + key;
						break;
					
				}
			}
			
			
			
			function openBox(){
				document.getElementById("box").style.display = "block";
			}
			
			function closeBox(){
				document.getElementById("box").style.display = "none";
			}
			
			//1.点击c，清除文本框的内容
			//2.点击数字和运算符，出现相关算式
			//3.点击=，计算表达式
			// key  键
			// function calc(key){
			// 	alert(key)
			// }
			
		</script>
		
	</body>
</html>
